﻿using System.Runtime.Serialization;
using XcoAppSpaces.Core;

namespace XcoAppSpaces.Serialization.Binary
{
	class XcoConcurrentSerializationSurrogate : ISerializationSurrogate
	{
		public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
		{
			var attr = (XcoConcurrentAttribute)obj;
			var mode = attr.MessageTransferMode;
			info.AddValue("mode", (byte)mode);
		}

		public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
		{
			var mode = (MessageTransferMode)(byte)info.GetValue("mode", typeof(byte));
			obj = new XcoConcurrentAttribute { MessageTransferMode = mode };
			return obj;
		}
	}
}